const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("ArrtibuteAssertFactory",async function () {
   
  it("ArrtibuteFactory constructor", async function () {
    const ArrtibuteAssertFactory = await ethers.getContractFactory("ArrtibuteAssertFactory");
    const option = 0;
    const arrtibuteAssertFactory = await ArrtibuteAssertFactory.deploy(option);
    console.log("[INFO}Factory address:"+(await arrtibuteAssertFactory.deployed()).address);
    expect(await arrtibuteAssertFactory.getTraitType()).to.equal(option);
  });

  it("ArrtibuteFactory NewArrtibuteAssert",async function(){

    const [owner, user1,user2] = await ethers.getSigners();

    const ArrtibuteAssertFactory = await ethers.getContractFactory("ArrtibuteAssertFactory");
    const trait_type = 0;
    const arrtibuteAssertFactory = await ArrtibuteAssertFactory.deploy(trait_type);
    await arrtibuteAssertFactory.deployed();
    const tx = await arrtibuteAssertFactory.NewArrtibuteAssert(
        "cris",
        "QmVVKDkMziAXLmSyfhFAF5ev9TNyXVe6dkMGA6YNbRcQSv",
        "QmXuz6bWxYuB1atjpYt1WJsiT2yfnJ38qHDXWur65fXAsR",
        10,
        "MonkeyKing Head",
        "HKH",
    );

     
    // const asserts = await arrtibuteAssertFactory.getArtistIssue(owner.address);
    const allasserts = await arrtibuteAssertFactory.getAsserts();
    console.log("[INFO] new Assert contract addr:"+allasserts[0]._assert.toString());
    // expect(asserts[0]).to.equal(allasserts[0]);

    //触发事件_NewArrtibuteAssert
    const AssertIndex  = await arrtibuteAssertFactory.nextAssertsCurrentIndex();
    //1.生成过滤结构
    const fileter =   arrtibuteAssertFactory.filters._NewArrtibuteAssert(null,AssertIndex,owner.address);
    
    //2.进行过滤
    const events = await arrtibuteAssertFactory.queryFilter(fileter,-2);
    console.log("[INFO] Event _NewArrtibuteAssert Info:"+Object.entries(events[0].args));

    expect(events[0].args.newArrtibuteAssert.toString()).to.equal(allasserts[0]._assert.toString());
  });
  


});